import sys
from main_ui import Ui_MainWindow
from PyQt5 import QtWidgets
import open3d as o3d
import numpy as np
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
import os

class MainWindow(QtWidgets.QMainWindow,Ui_MainWindow):
    def __init__(self,parent = None):
        super(MainWindow,self).__init__(parent)
        self.setupUi(self)
        self.pushButton_Show3D.clicked.connect(lambda : self.show3D())
        self.pushButton_ReadPic.clicked.connect(lambda: self.showpic())
        self.pushButton_run_test_ov_f.clicked.connect(lambda: self.CMD())
        self.pushButton_run_test_ov_s.clicked.connect(lambda: self.CMD2())
        self.pushButton_funsion.clicked.connect(lambda: self.Fusion())
    def CMD(self):
        # os.system("gnome-terminal -e 'bash -c \"python3 --version\" '")

        os.system("gnome-terminal -e 'bash -c \"cd ~/Desktop/GeoMVSnet/openvino;python test_ov_f.py;bash \" '")
        # os.system('start cmd.exe /K cd ./GeoMVSnet/GeoMVSnet/openvino')
    def CMD2(self):
    	os.system("gnome-terminal -e 'bash -c \"cd ~/Desktop/GeoMVSnet/openvino;python test_ov_s.py;bash \" '")
    def Fusion(self):
        os.system("gnome-terminal -e 'bash -c \"cd ~/Desktop/GeoMVSnet;bash scripts/dtu/fusion_dtu.sh;bash\" '")

    def show3D(self):
        # pcd = o3d.io.read_point_cloud("mvsnet001.ply")
        # o3d.visualization.draw_geometries([pcd])
        path = self.lineEdit_3Dmodel.text()
        pcd = o3d.io.read_point_cloud(path)
        vis = o3d.visualization.Visualizer()
        vis.create_window()
        opt = vis.get_render_option()
        opt.background_color = np.asarray([0, 0, 0])  # 黑色背景
        vis.add_geometry(pcd)
        vis.run()
        vis.destroy_window()

    def showpic(self):
        path = self.lineEdit_pic.text()
        img_name = path + "/" + "rect_001_3_r5000.png"
        self.label_photo.setPixmap(QPixmap(img_name))
        self.label_photo.setScaledContents(True)

        img_name = path + "/" + "rect_002_3_r5000.png"
        self.label_photo_2.setPixmap(QPixmap(img_name))
        self.label_photo_2.setScaledContents(True)
        img_name = path + '/' + "rect_003_3_r5000.png"
        self.label_photo_3.setPixmap(QPixmap(img_name))
        self.label_photo_3.setScaledContents(True)
        img_name = path + '/' + "rect_004_3_r5000.png"
        self.label_photo_4.setPixmap(QPixmap(img_name))
        self.label_photo_4.setScaledContents(True)
        img_name = path + '/' + "rect_005_3_r5000.png"
        self.label_photo_5.setPixmap(QPixmap(img_name))
        self.label_photo_5.setScaledContents(True)
        img_name = path + '/' + "rect_006_3_r5000.png"
        self.label_photo_6.setPixmap(QPixmap(img_name))
        self.label_photo_6.setScaledContents(True)
        img_name = path + '/' + "rect_007_3_r5000.png"
        self.label_photo_7.setPixmap(QPixmap(img_name))
        self.label_photo_7.setScaledContents(True)
        img_name = path + '/' + "rect_008_3_r5000.png"
        self.label_photo_8.setPixmap(QPixmap(img_name))
        self.label_photo_8.setScaledContents(True)
        img_name = path + '/' + "rect_009_3_r5000.png"
        self.label_photo_9.setPixmap(QPixmap(img_name))
        self.label_photo_9.setScaledContents(True)
        img_name = path + '/' + "rect_010_3_r5000.png"
        self.label_photo_10.setPixmap(QPixmap(img_name))
        self.label_photo_10.setScaledContents(True)
        img_name = path + '/' + "rect_011_3_r5000.png"
        self.label_photo_11.setPixmap(QPixmap(img_name))
        self.label_photo_11.setScaledContents(True)
        img_name = path + '/' + "rect_012_3_r5000.png"
        self.label_photo_12.setPixmap(QPixmap(img_name))
        self.label_photo_12.setScaledContents(True)
        img_name = path + '/' + "rect_013_3_r5000.png"
        self.label_photo_13.setPixmap(QPixmap(img_name))
        self.label_photo_13.setScaledContents(True)
        img_name = path + '/' + "rect_014_3_r5000.png"
        self.label_photo_14.setPixmap(QPixmap(img_name))
        self.label_photo_14.setScaledContents(True)
        img_name = path + '/' + "rect_015_3_r5000.png"
        self.label_photo_15.setPixmap(QPixmap(img_name))
        self.label_photo_15.setScaledContents(True)
        img_name = path + '/' + "rect_016_3_r5000.png"
        self.label_photo_16.setPixmap(QPixmap(img_name))
        self.label_photo_16.setScaledContents(True)
        img_name = path + '/' + "rect_017_3_r5000.png"
        self.label_photo_17.setPixmap(QPixmap(img_name))
        self.label_photo_17.setScaledContents(True)
        img_name = path + '/' + "rect_018_3_r5000.png"
        self.label_photo_18.setPixmap(QPixmap(img_name))
        self.label_photo_18.setScaledContents(True)
        img_name = path + '/' + "rect_019_3_r5000.png"
        self.label_photo_19.setPixmap(QPixmap(img_name))
        self.label_photo_19.setScaledContents(True)
        img_name = path + '/' + "rect_020_3_r5000.png"
        self.label_photo_20.setPixmap(QPixmap(img_name))
        self.label_photo_20.setScaledContents(True)
        img_name = path + '/' + "rect_021_3_r5000.png"
        self.label_photo_21.setPixmap(QPixmap(img_name))
        self.label_photo_21.setScaledContents(True)
        img_name = path + '/' + "rect_022_3_r5000.png"
        self.label_photo_22.setPixmap(QPixmap(img_name))
        self.label_photo_22.setScaledContents(True)
        img_name = path + '/' + "rect_023_3_r5000.png"
        self.label_photo_23.setPixmap(QPixmap(img_name))
        self.label_photo_23.setScaledContents(True)
        img_name = path + '/' + "rect_024_3_r5000.png"
        self.label_photo_24.setPixmap(QPixmap(img_name))
        self.label_photo_24.setScaledContents(True)
        img_name = path + '/' + "rect_025_3_r5000.png"
        self.label_photo_25.setPixmap(QPixmap(img_name))
        self.label_photo_25.setScaledContents(True)
        img_name = path + '/' + "rect_026_3_r5000.png"
        self.label_photo_26.setPixmap(QPixmap(img_name))
        self.label_photo_26.setScaledContents(True)
        img_name = path + '/' + "rect_027_3_r5000.png"
        self.label_photo_27.setPixmap(QPixmap(img_name))
        self.label_photo_27.setScaledContents(True)
        img_name = path + '/' + "rect_028_3_r5000.png"
        self.label_photo_28.setPixmap(QPixmap(img_name))
        self.label_photo_28.setScaledContents(True)
        img_name = path + '/' + "rect_029_3_r5000.png"
        self.label_photo_29.setPixmap(QPixmap(img_name))
        self.label_photo_29.setScaledContents(True)
        img_name = path + '/' + "rect_030_3_r5000.png"
        self.label_photo_30.setPixmap(QPixmap(img_name))
        self.label_photo_30.setScaledContents(True)
        img_name = path + '/' + "rect_031_3_r5000.png"
        self.label_photo_31.setPixmap(QPixmap(img_name))
        self.label_photo_31.setScaledContents(True)
        img_name = path + '/' + "rect_032_3_r5000.png"
        self.label_photo_32.setPixmap(QPixmap(img_name))
        self.label_photo_32.setScaledContents(True)
        img_name = path + '/' + "rect_033_3_r5000.png"
        self.label_photo_33.setPixmap(QPixmap(img_name))
        self.label_photo_33.setScaledContents(True)
        img_name = path + '/' + "rect_034_3_r5000.png"
        self.label_photo_34.setPixmap(QPixmap(img_name))
        self.label_photo_34.setScaledContents(True)
        img_name = path + '/' + "rect_035_3_r5000.png"
        self.label_photo_35.setPixmap(QPixmap(img_name))
        self.label_photo_35.setScaledContents(True)
        img_name = path + '/' + "rect_036_3_r5000.png"
        self.label_photo_36.setPixmap(QPixmap(img_name))
        self.label_photo_36.setScaledContents(True)
        img_name = path + '/' + "rect_037_3_r5000.png"
        self.label_photo_37.setPixmap(QPixmap(img_name))
        self.label_photo_37.setScaledContents(True)
        img_name = path + '/' + "rect_038_3_r5000.png"
        self.label_photo_38.setPixmap(QPixmap(img_name))
        self.label_photo_38.setScaledContents(True)
        img_name = path + '/' + "rect_039_3_r5000.png"
        self.label_photo_39.setPixmap(QPixmap(img_name))
        self.label_photo_39.setScaledContents(True)
        img_name = path + '/' + "rect_040_3_r5000.png"
        self.label_photo_40.setPixmap(QPixmap(img_name))
        self.label_photo_40.setScaledContents(True)
        img_name = path + '/' + "rect_041_3_r5000.png"
        self.label_photo_41.setPixmap(QPixmap(img_name))
        self.label_photo_41.setScaledContents(True)
        img_name = path + '/' + "rect_042_3_r5000.png"
        self.label_photo_42.setPixmap(QPixmap(img_name))
        self.label_photo_42.setScaledContents(True)
        img_name = path + '/' + "rect_043_3_r5000.png"
        self.label_photo_43.setPixmap(QPixmap(img_name))
        self.label_photo_43.setScaledContents(True)
        img_name = path + '/' + "rect_044_3_r5000.png"
        self.label_photo_44.setPixmap(QPixmap(img_name))
        self.label_photo_44.setScaledContents(True)
        img_name = path + '/' + "rect_045_3_r5000.png"
        self.label_photo_45.setPixmap(QPixmap(img_name))
        self.label_photo_45.setScaledContents(True)
        img_name = path + '/' + "rect_046_3_r5000.png"
        self.label_photo_46.setPixmap(QPixmap(img_name))
        self.label_photo_46.setScaledContents(True)
        img_name = path + '/' + "rect_047_3_r5000.png"
        self.label_photo_47.setPixmap(QPixmap(img_name))
        self.label_photo_47.setScaledContents(True)
        img_name = path + '/' + "rect_048_3_r5000.png"
        self.label_photo_48.setPixmap(QPixmap(img_name))
        self.label_photo_48.setScaledContents(True)
        img_name = path + '/' + "rect_049_3_r5000.png"
        self.label_photo_49.setPixmap(QPixmap(img_name))
        self.label_photo_49.setScaledContents(True)









if __name__ == '__main__':
    print(1)
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = MainWindow()
    MainWindow.show()
    sys.exit(app.exec_())
    # print("->正在加载点云... ")
    # pcd = o3d.io.read_point_cloud("mvsnet001.ply")
    # print(pcd)
    #
    # print("->正在可视化点云")
    # o3d.visualization.draw_geometries([pcd])


